//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//


import PkgCover.*;

public class CoodinateCover1 {
    private GaussProjection _GP;
    private double _X;
    private double _Y;
    private double _B;
    private double _L;
    private String _ErrMsg;
    private enumLocalCoordinateSys _lcs;

    public static void main(String[] args) {
        CoodinateCover1 CC = new CoodinateCover1(3, enumEllipseSys.WGS84, enumLocalCoordinateSys.BeiJingCJ);
        if (!CC.FunCover(121.495191023,31.2419292248)) {
            System.out.println("出现错误！" + CC.get_ErrMsg());
        }

        System.out.println("经纬度坐标（40.2321880683303, 116.523973513395）转换为城建坐标（" + CC.get_X() + ",Y坐标：" + CC.get_Y() + "）");
        if (!CC.FunAntiCover(CC.get_X(), CC.get_Y())) {
            System.out.println("出现错误！" + CC.get_ErrMsg());
        }

        System.out.println("反转后为：纬度为：" + CC.get_B() + "，经度为：" + CC.get_L());
    }

    public CoodinateCover1(int zoneWide, enumEllipseSys ellipse, enumLocalCoordinateSys lcs) {
        this._lcs = lcs;
        this._GP = new GaussProjection(ellipse, zoneWide);
    }

    public Boolean FunCover(double B, double L) {
        if (!this._GP.Projection(B, L, (double)0.0F)) {
            this._ErrMsg = "高斯投影失败：" + this._GP.get_ErrMsg();
            return false;
        } else {
            FPData oFPData;
            switch (this._lcs) {
                case BeiJingCJ:
                    LocalCoordinateSys LCS = new BeiJingCJ();
                    oFPData = LCS.getFPData(true, this._GP.get_Maridian());
                    break;
                default:
                    oFPData = null;
            }

            if (oFPData == null) {
                this._ErrMsg = "没有实例化FPData对象";
                return false;
            } else {
                this._X = oFPData.get_X() + oFPData.get_K() * this._GP.get_X() * Math.cos(oFPData.get_T()) - oFPData.get_K() * this._GP.get_Y() * Math.sin(oFPData.get_T());
                this._Y = oFPData.get_Y() + oFPData.get_K() * this._GP.get_X() * Math.sin(oFPData.get_T()) + oFPData.get_K() * this._GP.get_Y() * Math.cos(oFPData.get_T());
                return true;
            }
        }
    }

    public Boolean FunAntiCover(double x, double y) {
        Boolean bRtn = true;
        switch (this._lcs) {
            case BeiJingCJ:
                bRtn = this.BeiJintCJToWGS84(x, y);
                break;
            default:
                bRtn = false;
        }

        return bRtn;
    }

    private boolean BeiJintCJToWGS84(double x, double y) {
        boolean bRtn = true;
        LocalCoordinateSys LCS = new BeiJingCJ();
        FPData oFPData = LCS.getFPData(false, 117);
        this._X = oFPData.get_X() + oFPData.get_K() * x * Math.cos(oFPData.get_T()) - oFPData.get_K() * y * Math.sin(oFPData.get_T());
        this._Y = oFPData.get_Y() + oFPData.get_K() * x * Math.sin(oFPData.get_T()) + oFPData.get_K() * y * Math.cos(oFPData.get_T());
        if (!this._GP.AntiProjection(this._X, this._Y, 117)) {
            this._ErrMsg = "高斯投影失败：" + this._GP.get_ErrMsg();
            bRtn = false;
            return bRtn;
        } else {
            if (this._GP.get_L() < (double)1.5F && this._GP.get_L() > (double)-1.5F) {
                this._L = (double)117.0F + this._GP.get_L();
                bRtn = true;
            } else if (this._GP.get_L() > (double)1.5F) {
                this._B = this._GP.get_Lat();
                this._L = (double)117.0F + this._GP.get_L();
                this._ErrMsg = "超出投影范围，可能不准确";
                bRtn = false;
            } else {
                FPData oFPData2 = LCS.getFPData(false, 114);
                this._X = oFPData2.get_X() + oFPData2.get_K() * x * Math.cos(oFPData2.get_T()) - oFPData2.get_K() * y * Math.sin(oFPData2.get_T());
                this._Y = oFPData2.get_Y() + oFPData2.get_K() * x * Math.sin(oFPData2.get_T()) + oFPData2.get_K() * y * Math.cos(oFPData2.get_T());
                if (!this._GP.AntiProjection(this._X, this._Y, 114)) {
                    this._ErrMsg = "高斯投影失败：" + this._GP.get_ErrMsg();
                    bRtn = false;
                }

                this._L = (double)114.0F + this._GP.get_L();
                bRtn = true;
            }

            this._B = this._GP.get_Lat();
            return bRtn;
        }
    }

    public double get_X() {
        return this._X;
    }

    public double get_Y() {
        return this._Y;
    }

    public double get_B() {
        return this._B;
    }

    public double get_L() {
        return this._L;
    }

    public String get_ErrMsg() {
        return this._ErrMsg;
    }
}
